<template>
  <!-- eslint-disable -->
  <div class="cooperationArr">

    <div class="topArea">
      <div class="inputSearch">
        <el-input v-model="companyParams.s" placeholder="请输入企业名称关键词搜索" style="width: 280px;" prefix-icon="el-icon-search" clearable @keyup.enter.native="handleSearchTable" />
      </div>
    </div>
    <div class="middleArea">
      <el-radio-group v-model="companyParams.audit_status" @change="handleChoStatus">
        <el-radio-button :label="null">全部</el-radio-button>
        <el-radio-button :label="1">待合作</el-radio-button>
        <el-radio-button :label="2">已合作</el-radio-button>
        <el-radio-button :label="3">合作拒绝</el-radio-button>
      </el-radio-group>

      <div class="filter-container">
        <i class="el-icon-refresh-left refresh" @click="handleClearScreening"></i>
        <!-- <el-select v-model="companyParams.industry_id" placeholder="请选择行业" clearable class="inputWidth">
          <el-option
            v-for="item in tradeList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select> -->
        <el-cascader
          placeholder="请选择专业"
          :options="tradeList"
          :props="defaultProps"
          class="inputWidth"
          style="width: 300px;"
          clearable
          @change="handleCascaderChange"
        />
        <el-date-picker
          v-model="publishTime"
          style="width: 400px;"
          type="daterange"
          range-separator="至"
          value-format="yyyy-MM-dd HH:mm:ss"
          start-placeholder="开始审核时间"
          end-placeholder="结束审核时间">
        </el-date-picker>
        <el-button style="width:100px;margin-bottom: 20px;" @click="handleScreeningChange">筛选</el-button>
      </div>
    </div>

    <!-- 列表 -->
    <el-table :data="companyList" v-loading="loading" style="width: 100%">
      <el-table-column align="center" label="企业名称">
        <template slot-scope="{row}">
          <span>{{ row.company.name }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="社会信用统一码">
        <template slot-scope="{row}">
          <span>{{ row.company.credit_code }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="industryCategory" label="行业分类">
        <template slot-scope="{row}">
          <span>{{ row.company.industry.name }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="招聘者联系电话">
        <template slot-scope="{row}">
          <span>{{ row.company.contact_phone }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="审核状态">
        <template slot-scope="{row}">
          <span>{{ row.audit_status == 4 || row.audit_status == 5 ? '已合作' : (row.audit_status == 2  ? '合作拒绝' : (row.audit_status == 3 ? '终止合作' : '待合作')) }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="audit_at" label="审核时间"></el-table-column>
      <el-table-column align="center" label="操作">
        <template slot-scope="{row}">
          <div v-if="row.audit_status == 4 || row.audit_status == 5">
            <el-tooltip effect="dark" content="详情" placement="top-start">
              <span class="btnIcon document" @click="jumpIntoDetail(row.id)"></span>
            </el-tooltip>
            <el-tooltip effect="dark" content="中止合作" placement="top-start">
              <span class="btnIcon stopWork" @click="handleAuditCompany(row.id, 3)"></span>
            </el-tooltip>
            
          </div>
          <div v-else-if="row.audit_status == 2 || row.audit_status == 3">
            <el-tooltip effect="dark" content="详情" placement="top-start">
              <span class="btnIcon document" @click="jumpIntoDetail(row.id)"></span>
            </el-tooltip>
            <el-tooltip effect="dark" content="恢复合作" placement="top-start">
              <span class="btnIcon restore" @click="handleAuditCompany(row.id, 5)"></span>
            </el-tooltip>
            <!-- <el-tooltip effect="dark" content="删除" placement="top-start">
              <span class="btnIcon delete" @click="handleDeleteClick(row)"></span>
            </el-tooltip> -->
          </div>
          <div v-else>
            <el-tooltip effect="dark" content="详情" placement="top-start">
              <span class="btnIcon document" @click="jumpIntoDetail(row.id)"></span>
            </el-tooltip>
            <el-tooltip effect="dark" content="通过" placement="top-start">
              <span class="btnIcon pass" @click="handleAuditCompany(row.id, 4)"></span>
            </el-tooltip>
            <el-tooltip effect="dark" content="拒绝" placement="top-start">
              <span class="btnIcon refuse" @click="handleAuditCompany(row.id, 2)"></span>
            </el-tooltip>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange" 
      @current-change="handleCurrentChange" 
      :current-page.sync="companyParams.page" 
      :page-sizes="[10,20,30,50]" 
      :page-size="companyParams.limit" 
      layout="prev, pager, next, total, sizes, jumper"
      :total="total" 
      style="margin-top: 30px;"
    />
  </div>
</template>

<script>
import { getCompanies, auditCompany, deleteCompany, getIndustries } from '../../api/company'
export default {
  data() {
    return {
      tradeList: [{ // 行业列表
        id: '001',
        title: '计算机软件'
      }, {
        id: '002',
        title: '会计'
      }],
      is_active: 1,
      loading: false,
      companyParams: {
        page: 1,
        limit: 10,
        s: '', // 搜索条件
        industry_id: null, // 行业
        start_audit_at: null, // 审核开始时间
        end_audit_at: null, // 审核结束时间
        audit_status: null //  null--全部 1--待合作 2--已合作 3--拒绝
      },
      publishTime: [],
      companyList: [],
      total: null,
      defaultProps: {
        checkStrictly: true,
        children: 'children',
        label: 'name',
        value: 'id'
      }
    }
  },
  mounted() {
    this.getCompanyList()
    this.getIndustriesList()
  },
  methods: {
    // 选择父级菜单
    handleCascaderChange(value) {
      console.log('value', value)
      if (value) {
        this.companyParams.industry_id = value[value.length - 1]
      }
    },
    // 企业列表
    getCompanyList() {
      this.loading = true
      getCompanies(this.companyParams).then(res => {
        this.companyList = res.data
        this.total = res.meta.total
      }).finally(() => {
        this.loading = false
      })
    },
    // 获取行业
    getIndustriesList() {
      getIndustries().then(res => {
        this.tradeList = res
      })
    },
    // 分页
    handleSizeChange(val) {
      this.companyParams.limit = val
      this.getCompanyList()
    },
    handleCurrentChange(val) {
      this.companyParams.page = val
      this.getCompanyList()
    },
    // 编辑
    handleEditStudent(row) {
      this.$router.push({
        path: './edit',
        query: {
          data: JSON.stringify(row)
        }
      })
    },
    // 点击'筛选'按钮
    handleScreeningChange() {
      this.companyParams.page = 1
      this.companyParams.limit = 10
      this.companyParams.s = ''
      this.companyParams.audit_status = null
      this.companyParams.start_audit_at = this.publishTime ? this.publishTime[0] : ''
      this.companyParams.end_audit_at = this.publishTime ? this.publishTime[1] : ''
      this.getCompanyList()
    },
    // 点击'清空'按钮
    handleClearScreening() {
      this.publishTime = []
      this.companyParams.industry_id = null
      this.companyParams.start_audit_at = null
      this.companyParams.end_audit_at = null
    },
    // 点击'搜索'按钮
    handleSearchTable() {
      this.companyParams.page = 1
      this.companyParams.limit = 10
      this.companyParams.industry_id = null
      this.companyParams.start_audit_at = null
      this.getCompanyList()
    },
    handleChoStatus(type) {
      this.companyParams.page = 1
      this.companyParams.limit = 10
      this.getCompanyList()
    },
    // 详情
    jumpIntoDetail(id) {
      this.$router.push({
        path: './detail',
        query: { id }
      })
    },
    // 审核企业
    handleAuditCompany(id, type) {
      let aletMsg = ''
      if (type === 2) {
        aletMsg = '是否拒绝该企业'
      } else if (type === 3) {
        aletMsg = '是否与该企业中止合作'
      } else if (type === 4) {
        aletMsg = '是否确认通过审核'
      } else if (type === 5) {
        aletMsg = '是否与该企业恢复合作'
      }
      this.$confirm(aletMsg, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading = true
        auditCompany(id, type).then(() => {
          this.$message({
            type: 'success',
            message: '操作成功！'
          })
          this.getCompanyList()
        }).finally(() => {
          this.loading = false
        })
      }).catch(() => {
      })
    },
    // '删除'
    handleDeleteClick(row) {
      this.$confirm('是否确认删除该企业', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteCompany(row.id).then(() => {
          this.$message({
            type: 'success',
            message: '企业信息删除成功'
          })
        }).finally(() => {
          this.getCompanyList()
        })
      }).catch(() => {
      })
    }
  }
}
</script>

<style lang="scss">
  $defaultColor: #0A2045;
  .cooperationArr {
    padding: 30px;
    .topArea {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 30px;
      .el-input--suffix .el-input__inner {
        padding-right: 0;
      }
    }
    .middleArea {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 30px;
      .el-radio-button__orig-radio:checked+.el-radio-button__inner {
        background-color: #F1F7FF;
        border: none;
        color: #0C66FF;
        box-shadow: none;
      }
      .el-radio-button__inner {
        border: none;
        border-radius: 8px;
        color: #6C798F;
      }
      .el-radio-group {
        border: 1px solid #E1E4EB;
        border-radius: 8px;
      }

      .filter-container {
        .refresh {
          color: #B2B7C2;
          font-size: 20px;
          margin-right: 10px;
          cursor: pointer;
        }
        .inputWidth {
          margin-right: 10px;
          width: 224px;
          height: 38px;
          line-height: 38px;
        }
      }
    }
  }
  .el-button:focus, .el-button:hover {
    color: #0C66FF;
    border-color: #0C66FF;
    background-color: #fff;
  }
  .el-button--primary {
    color: #FFF;
    background-color: #0C66FF;
    border-color: #0C66FF;
  }
  .el-button--small {
    border-radius: 8px;
  }
  .el-button--primary:hover {
    color: #fff;
    background-color: #0951CC;
    border-color: #0951CC;
  }
  .btnIcon {
    display: inline-block;
    width: 24px;
    height: 24px;
    cursor: pointer;
    margin-right: 10px;
  }
  // 通过
  .pass {
    background: url('../../assets/btn/icon_approved.png') no-repeat center center;
  }
  .pass:hover {
    background: url('../../assets/btn/icon_approved_s.png') no-repeat center center;
  }
  // 企业详情
  .document {
    background: url('../../assets/btn/icon_information.png') no-repeat center center;
  }
  .document:hover {
    background: url('../../assets/btn/icon_information_s.png') no-repeat center center;
  }
  // 拒绝
  .refuse {
    background: url('../../assets/btn/icon_refuse.png') no-repeat center center;
  }
  .refuse:hover {
    background: url('../../assets/btn/icon_refuse_s.png') no-repeat center center;
  }
  // 中止合作
  .stopWork {
    background: url('../../assets/btn/icon_Cancelcooperation.png') no-repeat center center;
  }
  .stopWork:hover {
    background: url('../../assets/btn/icon_Cancelcooperation_s.png') no-repeat center center;
  }
  // 删除
  .delete {
    background: url('../../assets/btn/icon_delete.png') no-repeat center center;
  }
  .delete:hover {
    background: url('../../assets/btn/icon_delete_s.png') no-repeat center center;
  }
  // 恢复合作
  .restore {
    background: url('../../assets/btn/icon_restore cooperation.png') no-repeat center center;
  }
  .restore:hover {
    background: url('../../assets/btn/icon_restore cooperation_s.png') no-repeat center center;
  }
</style>
